home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / newmat08.zip / TMT8.CPP < prev    next >
C/C++ Source or Header  |  1995-01-13  |  3KB  |  89 lines

  1.  
  2. //#define WANT_STREAM
  3.  
  4.  
  5. #include "include.h"
  6.  
  7. #include "newmat.h"
  8.  
  9.  
  10. /**************************** test program ******************************/
  11.  
  12. void Print(const Matrix& X);
  13. void Print(const UpperTriangularMatrix& X);
  14. void Print(const DiagonalMatrix& X);
  15. void Print(const SymmetricMatrix& X);
  16. void Print(const LowerTriangularMatrix& X);
  17.  
  18. void Transposer(const GenericMatrix& GM1, GenericMatrix&GM2)
  19.    { GM2 = GM1.t(); }
  20.  
  21.  
  22. void trymat8()
  23. {
  24. //   cout << "\nEighth test of Matrix package\n";
  25.    Tracer et("Eighth test of Matrix package");
  26.    Exception::PrintTrace(TRUE);
  27.  
  28.    int i;
  29.  
  30.  
  31.    DiagonalMatrix D(6);
  32.    for (i=1;i<=6;i++)  D(i,i)=i*i+i-10;
  33.    DiagonalMatrix D2=D;
  34.    Matrix MD=D;
  35.  
  36.    DiagonalMatrix D1(6); for (i=1;i<=6;i++) D1(i,i)=-100+i*i*i;
  37.    Matrix MD1=D1;
  38.    Print(Matrix(D*D1-MD*MD1));
  39.    Print(Matrix((-D)*D1+MD*MD1));
  40.    Print(Matrix(D*(-D1)+MD*MD1));
  41.    DiagonalMatrix DX=D;
  42.    {
  43.       Tracer et1("Stage 1");
  44.       DX=(DX+D1)*DX; Print(Matrix(DX-(MD+MD1)*MD));
  45.       DX=D;
  46.       DX=-DX*DX+(DX-(-D1))*((-D1)+DX);
  47. #ifdef __GNUG__
  48.       Matrix MX = Matrix(MD1);
  49.       MD1=DX+(MX.t())*(MX.t()); Print(MD1);
  50. #else
  51.       MD1=DX+(Matrix(MD1).t())*(Matrix(MD1).t()); Print(MD1);
  52. #endif
  53.       DX=D; DX=DX; DX=D2-DX; Print(DiagonalMatrix(DX));
  54.       DX=D;
  55.    }
  56.    {
  57.       Tracer et1("Stage 2");
  58.       D.Release(2);
  59.       D1=D; D2=D;
  60.       Print(DiagonalMatrix(D1-DX));
  61.       Print(DiagonalMatrix(D2-DX));
  62.       MD1=1.0;
  63.       Print(Matrix(MD1-1.0));
  64.    }
  65.    {
  66.       Tracer et1("Stage 3");
  67.       //GenericMatrix
  68.       LowerTriangularMatrix LT(4);
  69.       LT << 1 << 2 << 3 << 4 << 5 << 6  << 7 << 8 << 9 << 10;
  70.       UpperTriangularMatrix UT = LT.t() * 2.0;
  71.       GenericMatrix GM1 = LT;
  72.       LowerTriangularMatrix LT1 = GM1-LT; Print(LT1);
  73.       GenericMatrix GM2 = GM1; LT1 = GM2; LT1 = LT1-LT; Print(LT1);
  74.       GM2 = GM1; LT1 = GM2; LT1 = LT1-LT; Print(LT1);
  75.       GM2 = GM1*2; LT1 = GM2; LT1 = LT1-LT*2; Print(LT1);
  76.       GM1.Release();
  77.       GM1=GM1; LT1=GM1-LT; Print(LT1); LT1=GM1-LT; Print(LT1);
  78.       GM1.Release();
  79.       GM1=GM1*4; LT1=GM1-LT*4; Print(LT1);
  80.       LT1=GM1-LT*4; Print(LT1); GM1.CleanUp();
  81.       GM1=LT; GM2=UT; GM1=GM1*GM2; Matrix M=GM1; M=M-LT*UT; Print(M);
  82.       Transposer(LT,GM2); LT1 = LT - GM2.t(); Print(LT1);
  83.       GM1=LT; Transposer(GM1,GM2); LT1 = LT - GM2.t(); Print(LT1);
  84.       GM1 = LT; GM1 = GM1 + GM1; LT1 = LT*2-GM1; Print(LT1);
  85.    }
  86.  
  87. //   cout << "\nEnd of eighth test\n";
  88. }
  89.